class RaceCombatAi extends RaceAi;

var Pawn playerPawn;

DefaultProperties
{
	bIsPlayer = true;
	bAdjustFromWalls=true;
}

auto state Moving
{
	function RaceTick()
	{
		local RaceCar raceCar;
		//local Vector lookVector;

		raceCar = RaceCar(Pawn);

		//`log("RacePawn "$v$" PlayerPawn "$playerPawn);
		
		raceCar.StopFiring();
		//FindNearestEnemy();
		if(car == none || playerPawn==none) return;
		
		raceCar.StartFire(0);	
		
		
		//GotoState('FireAtwill');
	}

	event SeePlayer(Pawn seen)
	{
		//MoveToward(Pawn,playerPawn);
		playerPawn = seen;
	}

	//damage


	Moving:
		//if(playerPawn != none)
		//	FireWeaponAt(playerPawn);

}

state FireAtwill
{
Begin:
	MoveToward(Pawn,playerPawn);	
	//FireWeaponAt(playerPawn);
	GotoState('Moving');
	
}


function FindNearestEnemy()
{
	local Controller C;
	local float prevDistance,currentDistance;
	local bool first;
	first = true;

	foreach WorldInfo.AllControllers(class'Controller', C)
	{	
		
		if (C.bIsPlayer && !C.IsDead() && C != self)
		{
			currentDistance = VSize(Location - C.Pawn.Location);
			
			if( currentDistance < prevDistance || first)
			{
				first = false;
				prevDistance= currentDistance;
				playerPawn = C.Pawn;

				`log("found "$C.Pawn);
			}
		}
	}
}